$(function () {

    function check(validatorDom) {
        if (validatorDom.attr("name") === "jzSpeed" && validatorDom.val() < 0.00001) {
            return {
                "retBool": true,
                "msg": "校准转速长度必须大于0"
            };
        }
        if (validatorDom.attr("name") === "jzQuan" && validatorDom.val() < 0.00001) {
            return {
                "retBool": true,
                "msg": "校准圈数长度必须大于0"
            };
        }
    }

    //拉取数据
    Request.builder()
        .url(CALIBRATION_SETTING_DETAIL)
        .isToken(true)
        .callback(function (e) {
            Form.setValues($(".card-body"), e.data);
        }).get();

    $("#submit").click(function () {
        var data = Form.getValues($(".site-form"));
        Validator.builder()
            .dom($(".site-form"))
            .customValidate(check)
            .customSubmit(function (e) {
                if (!e){
                    return false;
                }
                Request.builder()
                    .url(CALIBRATION_SETTING_UPDATE)
                    .data(data)
                    .isToken(true)
                    .callback(function (e) {
                        if (e.code === "00000") {
                            LayerUtil.successMsg("修改成功~")
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000)
                        } else {
                            LayerUtil.failMsg(e.msg != null ? e.msg : "修改失败")
                        }
                    }).post();
            }, null).do();
    });
});
